package com.cn.bukeManage.controller;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cn.bukeManage.pojo.Indent;
import com.cn.bukeManage.pojo.page.Page;
import com.cn.bukeManage.service.OrdersService;


@Controller
@RequestMapping("/orders")
public class OrdersController {
	@Resource
	private OrdersService orderservice;
	//点击顾客订单跳转页面
	
	
	/**
	 * 已完成订单（自己的和下属的订单）
	 * @param model
	 * @param currentPage
	 * @param status
	 * @param afterSale
	 * @return
	 */
	@RequestMapping("/toNewOrders")
	public String toNewOrders(Model model,Integer currentPage,Integer status,Integer afterSale){
		//List<Map<String,Object>> list=indentService.getAllOrdersByStatus(model,currentPage,status,afterSale);
		List<Map<String,Object>> list=orderservice.showIndents(currentPage,status,model);
		model.addAttribute("oneMenu", "orders");
		model.addAttribute("twoMenu", "newOrders");
		model.addAttribute("orders",list);
		if(status==3){
			return "orders/customerOrders2";  //已付款
		}else if(status==8){
			return "orders/customerOrders3";  //系统已处理
		}
//		else if(status==3){
//			return "orders/customerOrders4";//配货中
//		}else if(status==4){
//			return "orders/customerOrders5";//配货完成
//		}
//		else if(status==7){
//			return "orders/customerOrders8";//退款未处理
//		}
		else if(status==14){
			return "orders/customerOrders6";//已发货
		}else if(status==15){
			return "orders/customerOrders10";//已收货--已完成
		}else if(status==7){
			return "orders/customerOrders9";//已退款
		}else{  //未付款
			return "orders/customerOrders";
		}	
	}
	//点击顾客订单的状态返回他的所有订单
//	@RequestMapping("/getOrdersOfDataByStatus")
//	@ResponseBody
//	public List<Map<String,Object>> toOrdersAndIndent(Model model, Integer currentPage,Integer status,Integer afterSale){
//		List<Map<String,Object>> list=orderservice.getAllOrdersByStatus(model,currentPage,status,afterSale);
//		return list;		
//	}
	
	
	//点击售后新订单, 返回所有数据
	@RequestMapping("/getGoodsOfAfterSale")
	public String getGoodsOfAfterSale(Model model,Integer currentPage,Integer status){
		List<Map<String,Object>> list=orderservice.getGoodsOfAfterSaleByNew(model,currentPage,status);
		model.addAttribute("oneMenu", "orders");
		model.addAttribute("twoMenu", "customerServiceOrders");
		model.addAttribute("goods",list);
		if(status==0){
			return "orders/customerServiceOrders";
		}else{
			return "orders/customerServiceOrders2";
		}
		
	}
	//售后新订单分页
	@RequestMapping("/getPageOfGoodsOfAfterSale")
	@ResponseBody
	public Page getPageOfGoodsOfAfterSale(Integer currentPage){
		Page page =orderservice.getPageOfGoodsOfAfterSale(currentPage);
		return page;
	}
	
	//根据订单号得到所有商品详情
	@RequestMapping("/getGoodOfAccByOrderId")
	@ResponseBody
	public List<Map<String,Object>> getGoodOfAccByOrderId(Integer orderId){
		List<Map<String,Object>> list=orderservice.getGoodsOfAccByOrderId(orderId);
		return list;
	}
	//根据订单号更改订单的状态
	@RequestMapping("/updateOrderStatusByOrderIdAndStatus")
	@ResponseBody
	public Integer updateOrderStatusByOrderIdAndStatus(Integer orderId,Integer status){
		Integer integer=orderservice.updateOrderStatusByOrderIdAndStatus(orderId,status);
		return integer;
	}
	//审核订单
	@RequestMapping("/shenHeDingDan")
	@ResponseBody
	public Integer shenHeDingDan(Integer orderId,Integer status){
		Integer integer=orderservice.shenHeDingDan(orderId,status);
		return integer;
	}
	//根据订单号得到测量费用
	@RequestMapping("/getAddMoneyByIndentId")
	@ResponseBody
	public Indent getAddMoneyByIndentId(Integer indentId){
		Indent indent=orderservice.getIndentByIndentId(indentId);
		return indent;
	}
	//保存增加的费用
	@RequestMapping("/saveAddMoneyByIdAndMoney")
	@ResponseBody
	public Integer saveAddMoneyByIdAndMoney(Indent indent){
		Integer integer=orderservice.saveAddMoneyByIdAndMoney(indent);
		return integer;
	}
	//根据安装测量订单号中止或者开启该
	@RequestMapping("toStopOrStartIndent")
	@ResponseBody
	public Integer toStopOrStartIndent(Integer indentId,Integer status){
		Integer integer=orderservice.toStopOrStartIndent(indentId,status);
		return integer;
	}
	//根据订单号得到工人的详细信息
	@RequestMapping("getWorkerByIndentId")
	@ResponseBody
	public Map<String,Object> getWorkerByIndentId(Integer indentId){
		Map<String, Object> worker=orderservice.getWorkerByIndentId(indentId);
		return worker;
	}
	//根据订单号得到它的所有详细信息
	@RequestMapping("getOrderByOrderId")
	@ResponseBody
	public Map<String,Object> getOrderByOrderId(Integer orderId){
		Map<String,Object> map=orderservice.getOrderByOrderId(orderId);
		return map;
	}
	//根据订单号修改该订单的所有配货方式
	@RequestMapping("updateSupplyMethod")
	@ResponseBody
	public Integer updateSupplyMethod(Integer orderId,@RequestParam(value = "goodsIdArray[]") String[] goodsIdArray,
			@RequestParam(value = "noGoodsIdArray[]") String[] noGoodsIdArray){
		Integer integer=orderservice.updateSupplyMethod(orderId,goodsIdArray,noGoodsIdArray);
		return integer;
	}
}
